;import mysql from "mysql";
let pool=mysql.createPool(require("../../config"));
//用个函数接受所有结果
async function queryAsync() {
    return await query(...arguments);
}
function query(sql,params) {
    return new Promise((resolve,reject)=>{
       //创建新连接
        pool.getConnection((err,conn)=>{
            if(err){
                console.log("连接失败");
                reject(err);
            }
            conn.query(sql,params,(err,res,file)=>{
                conn.release();
                if(err){
                    console.log("执行失败");
                    reject(err);
                }
                resolve(res);
            })
        })
    })
}

module.exports={
    query,
    queryAsync
}